/**
 * 
 */
package cn.terrence.myoauth2.client.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.common.OAuth;
import org.apache.oltu.oauth2.common.message.types.ResponseType;

import cn.terrence.myoauth2.common.Constant;

/**
 * @author cuihua022
 * 发起授权请求Servlet 
 */
public class AuthCodeGetterServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5156266234238668239L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try{
			OAuthClientRequest orequest = OAuthClientRequest
					   .authorizationLocation(Constant.TEST_SERVER_URL+"/buildAuthCode")
					   .setClientId("myAppId")
					   .setRedirectURI(Constant.TEST_CLIENT_URL+"/receiveAuthCode")
					   .setParameter(OAuth.OAUTH_RESPONSE_TYPE,ResponseType.CODE.toString())
					   .buildQueryMessage();
			response.sendRedirect(orequest.getLocationUri());
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	

}
